﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using DBLClient.DBLAdminConfigService;
namespace DBLClient.DBLForm
{
    public partial class EditAdminForm : Form
    {
        public EditAdminForm()
        {
            InitializeComponent();
        }

        private void buttonSearch_Click(object sender, EventArgs e)
        {
            string searchWord = textBoxSearchWord.Text;
            AdminConfigService admin = new AdminConfigService();
            DataSet ds = admin.GetAdminByAdminName(searchWord);
            dataGridView1.DataSource = ds.Tables[0];
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            AddAdminForm add = new AddAdminForm("A",0);
            add.Show();
        }

        private void buttonEdit_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                MessageBox.Show("请选中要编辑的一行");
                return;
            }
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells["columnID"].Value);
            AddAdminForm update = new AddAdminForm("U",id);
            update.Show();
        }

        private void buttonDel_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                MessageBox.Show("请选中要删除的一行");
                return;
            }
            
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells["columnID"].Value);
            AdminConfigService admin = new AdminConfigService();
            int affectnum = admin.DelAdminByID(id);
            if (affectnum == 1)
            {
                MessageBox.Show("删除成功");
            }
            else
            {
                MessageBox.Show("删除失败");
            }
            
        }
    }
}
